/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.io.IOException;

/**
 *
 * @author Administrator
 */
public class Prova {
    static MainFrame mf;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        mf = new MainFrame();
        
    }
    
    public static String encode(String st,int k) {
        StringBuilder s = new StringBuilder(st);
        for(int i = 0; i<s.length() ; i++) {
            char c = s.charAt(i);
            if(Character.isLetterOrDigit(c)) {
                if((c>'z'-k && c<='z') || (c>'Z'-k && c<='Z'))
                    c = (char) (c - ('z' - 'a') + k - 1);
                else if(c>'9'-k && c<'9')
                    c = (char) (c - ('9' - '0') + k - 1);
                else c+=k;
                s.setCharAt(i, c);
            }
        }
        return s.toString();
    }
    
    public static String decode(String st,int k) {
        StringBuilder s = new StringBuilder(st);
        for(int i = 0; i<s.length() ; i++) {
            char c = s.charAt(i);
            if(Character.isLetterOrDigit(c)) {
                if((c>='a' && c<'a'+k) || (c>='A' && c<'A'+k))
                    c = (char) (c + ('z' - 'a') - k + 1);
                else if(c>='0' && c<'0' + k)
                    c = (char) (c + ('9' - '0') - k + 1);
                else c-=k;
                s.setCharAt(i, c);
            }
        }
        return s.toString();
    }
}
